/*
* EP-Tracing System : a tool to trace mountain hike.           .kNNx
* Copyright (C) 2009  Raffaello Brondi                         'KNNNk
*                                                             ,XNNNl
* This program is free software:                             ,XNN0'
* you can redistribute it and/or modify                     ,XNNx.
* it under the terms of the                                'XNNl
* GNU General Public License                              .KNN:                     ..
* as published by                                        .0NNo                    .ONNO.
* the Free Software Foundation,                          xNNN.  :dkd,            .KNNNN;
* either version 3 of the License, or                   :NNNK ;XNNNNNo          ,KNNNX:
* (at your option) any later version.                   xNNNNcXNNNNNNk         cNNNNx.
*                                                       ,XNNNNNNNNNNX'       .xNNNK;
*                                                        .lKNNNNNNNK'       :KNNNo
*                                                          ;kNNNNNKxl;'.'l0NNNk.
* This program is distributed in                          .'  .:xXNNNNNNNNNNNO,
* the hope that it will be useful,                       :NNXd'   ,oONNNNNNk,
* but WITHOUT ANY WARRANTY;                              xNNNNN0c.    .;;,.
* without even the implied warranty of                   kNNNNNNNXd'
* MERCHANTABILITY or                                     xNNNNNNNNNNOc.
* FITNESS FOR A PARTICULAR PURPOSE.                      xNNNNNNNNNNNNXd.
* See the GNU General Public License                     ONNNN0.,o0NNNNNNl
* for more details.                                      0NNNNd    kNNNNNX.
*                                                        KNNNNl   oNNNNNXc
*                                                       .XNNNN:  dNNNNNx.
* You should have received a copy                       .XNNNN; lNNNNO'
* of the GNU General Public License                     .XNNNN; 'dxo'
* along with this program.                              .XNNNN;
* If not, see <http://www.gnu.org/licenses/>.            0NNNN:
*                                                        kNNNNc
*                                                        oNNNNd
*                                                        ;NNNN0
* Contact: rbrondi@gmail.com                             .XNNNN;
*                                                         kNNNNd
*                                                         .coo:.
*/

package EP.UI;

import java.util.Timer;
import java.util.TimerTask;
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Gauge;

/**
 *
 * @author Raffaello Brondi
 */
public class Messages {

    /**
     * Shows a alert that Location API is not supported.
     */
    public static void showApiNotSupported() {
        Alert alert = new Alert("Information",
                "Device do not support Location API.", null, AlertType.INFO);
        EPTS.getDisplay().setCurrent(alert);
    }

    /**
     * Shows a alert that Location data is not available.
     */
    public static void showLocationDataNotAvailable() {
        Alert alert = new Alert("Information",
                "Location data is not yet available.", null, AlertType.INFO);
        EPTS.getDisplay().setCurrent(alert);
    }

    /**
     * Show a status dialog informing about state of location provider.
     */
    public static Alert showLooking4Provider() {
        final Gauge indicator = new Gauge(null, false, 50, 1);
        indicator.setValue(Gauge.CONTINUOUS_RUNNING);

        final Alert alert = new Alert("Information", "Please wait, looking for location provider...", null, AlertType.INFO);
        alert.setIndicator(indicator);
        alert.setTimeout(Alert.FOREVER);

        // Create a timer that fires off every 1000 milliseconds
        Timer timer = new Timer();
        timer.scheduleAtFixedRate(new TimerTask() {

            public void run() {
                if(EPTS.getDisplay().getCurrent() != alert)
                    cancel();

                if (indicator.getValue() < indicator.getMaxValue()) {
                    indicator.setValue(indicator.getValue() + 1);
                } else {
                    indicator.setValue(1);
                }
            }
        }, 0, 500);

        return alert;
    }

    public static Alert showNoProvider4Criteria(){
        Alert alert = new Alert("Warning", "No provider found with the specified criteria.", null, AlertType.WARNING);
        alert.setTimeout(Alert.FOREVER);
        return alert;
    }

    public static Alert showProvidersOutOfService(){
        Alert alert = new Alert("Warning", "All the providers are out of service at the moment.", null, AlertType.WARNING);
        alert.setTimeout(Alert.FOREVER);
        return alert;
    }

    /**
     * Shows an alert notifing that there is no details for such a file
     */
    public static void showNoDetails4File() {
        Alert alert = new Alert("No details available",
                "No details available for such a file.", null, AlertType.WARNING);
        EPTS.getDisplay().setCurrent(alert);
    }

    /**
     * Shows an alert notifing that you can not load such a file in the compass.
     */
    public static void showNotLoadableFile() {
        Alert alert = new Alert("Error",
                "You can not load such a file in the compass.", null, AlertType.ERROR);
        EPTS.getDisplay().setCurrent(alert);
    }

    /**
     * Shows an alert notifing that you can not load such a file in the compass.
     */
    public static void showNotWellFormedEPH() {
        Alert alert = new Alert("Error",
                "The EPH file is not well formed. Please check the file.", null, AlertType.ERROR);
        EPTS.getDisplay().setCurrent(alert);
    }
}
